from gideon.service.starlabs import GideonHandler, Option


class StudentHandler(GideonHandler):
    display_manager_button = []
    display_list = ["customer", "qq", "mobile", "emergency_contract", "class_list", "score", "student_status", "memo"]
    display_operation_button = ["edit", ]
    search_list = ["customer__name", "qq", "mobile"]
    search_group = [Option("class_list", text_func=lambda x: f"{x.school.name}-{x}"), ]

    def show_score_field(self, obj=None, is_title=False, *args, **kwargs):
        title = "积分"
        if is_title:
            return title
        if obj:
            url = self.reverse_handle_url(self.request, "supergirl_scorerecord_list", student_key=obj.key)
            return {"href": url, "title": obj.score}, "body", {"type": "link", "target": "_blank"}
        return "scord function error"

    def show_class_list_field(self, obj=None, is_title=False, *args, **kwargs):
        return self.format_m2m_field(obj, "class_list", is_title, *args, **kwargs)
